<template>
	<view>
		 <view :style="'height:'+statusBarHeight+'px;'"></view>
		<u-loading-page :loading="loading" style="padding: 0;margin: 0;height: 100vh;width: 100vw;"></u-loading-page>
		<view class="background purchase-list">
			<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower"
				@scrolltoupper="scrolltoupper">
				<view class="" style="padding: 0px 12px 10px 12px;">
					<view class="el_selects flex jcfe">
						<!-- <u-select v-model="selectValue" @change="optionClick" placeholder="请选择" size="mini"
									style="width: 134px;">
									<u-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel"
										:value="item.dictValue">
									</u-option>
								</u-select> -->
						<!-- <u-picker :show="show" :columns="options" @change="optionClick" keyName="dictLabel">
						</u-picker>
						<u-button @click="show = true">打开</u-button> -->
						<view class="" @tap="show = true">
							<u-input readonly v-model="selectValue" type="select"  placeholder="请选择" />
							<u-picker closeOnClickOverlay @cancel="show = false" :show="show" :columns="options" @confirm="optionClick" keyName="dictLabel"
								placeholder="请选择">
							</u-picker>
						</view>
					</view>
					<ComponyHearder :data="ComponyHearderData" />
					<view class="index_header">
						<view class="index_header_top flex">
							<text @click="headerClick(item,index)" v-for="(item,index) in HeadersData" :key="index"
								:class="indexHeaderValue==index?'indexBack1 fontw700 fonts14':'indexBack2 fonts14'">{{item.label}}{{item.number>0?`(${item.number})`:``}}</text>
						</view>
						<view class="index_header_bottom" v-if="indexHeaderValue!=2">
							<view class="" style="width: 70%;">
								<u-input style="height: 18px;width: 90%;" placeholder="搜索职位\公司名称"
									v-model="form.searchValue">
								</u-input>
							</view>
							<view class="" style="width: 25%;height: 18px;margin-left: 16px;">
								<u-button type="primary" style="height: 32px;width: 100%;" @click="search()">搜索
								</u-button>
							</view>


						</view>
					</view>
					<view class="" v-if="indexHeaderValue!=2" @click="detail(item)" v-for="item in datas">
						<Inventory :data="item" />
					</view>
					<view class="Inventory_compony" v-if="indexHeaderValue==2">
						<p class="fontc3d fonts12 fontz">
							{{homeData[1].contentContents}}
						</p>
						<image v-for="item in imageData" :src="item" mode=""
							style="max-width: 100%;margin: auto;margin:10px 0;"></image>
					</view>
					<view class="" v-if="indexHeaderValue!=2">
						<p class="more" v-if="onMore">没有更多了~</p>
						<p class="more" v-if="loading">加载中...</p>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>





</template>

<script>
	import {
		dictFunAll
	} from "@/util/dictionary.js"
	import {
		getselect,
		getlist,
		homeConfiguration
	} from "@/api/index"
	import ComponyHearder from "../components/ComponyHeader.vue"
	import Inventory from "../components/Inventory.vue"
	export default {
		components: {
			ComponyHearder,
			Inventory,
		},
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync ().statusBarHeight,
				show: false,
				onMore: false,
				loading: false,
				totalBool: true,
				status: 'more',
				indexHeaderValue: 0,
				input3: "",
				HeadersData: [{
						label: "全部职位",
						number: "0",
						id: 0
					},
					{
						label: "紧急职位",
						number: "0",
						id: 1
					},
					{
						label: "公司信息",
						number: "0",
						id: 2
					}
				],
				title: 'Hello',
				datas: [],
				selectValue: "",
				options: [],
				form: {
					positionName: "", //职位名称
					pageNum: 1,
					pageSize: 10,
					urgentPosition: "",
					positionType: ""
				},
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				homeData: [],
				homeDataTitle: "",
				imageData: [],
				ComponyHearderData: {
					img: "",
					title: "",
					companyType: "",
					companySize: "",
					companyIndustry: "",
					address: "",
					bool: 0
				}
			}
		},
		onShow() { //没次回到页面都会调用下拉刷新
		  uni.startPullDownRefresh()
		},
		onReachBottom() {
			console.log("上拉加载");
			console.log("页码:", this.form.pageNum);
			if (this.indexHeaderValue == 2) {
				return
			}
			if (!this.totalBool) {
				this.onMore = true
				this.totalBool = false
				setTimeout(() => {
					this.onMore = false
				}, 2000)
				return
			}
			this.form.pageNum++;
			this.getlistApi(this.form)
		},
		onLoad() {
			console.log(this.$u.config.v); //产看uview的版本信息
			// this.loading = true
			this.getselectApi_()


		},
		onPullDownRefresh() {
			console.log("下拉刷新");
			this.form.pageNum = 1
			this.getlistApi(this.form)
		},
		methods: {
			search() {
				this.form.pageNum = 1
				this.getlistApi(this.form)
			},
			headerClick(item, index) {
				this.form.pageNum = 1
				this.indexHeaderValue = index
				if (this.indexHeaderValue == 0) {
					this.form.urgentPosition = ""
				} else {
					this.form.urgentPosition = 0
				}
				if (this.indexHeaderValue == 2) {
					return
				}
				this.getlistApi(this.form)
			},
			evaluationClick(item) {
				uni.navigateTo({
					url: "/pages/index/evaluation/evaluation?id=" + item + "&type=0"
				})
			},
			getlistApi(params) {
				this.loading = false
				getlist(params).then((res) => {
					this.loading = true
					this.show=false
					console.log(res);
					if (this.form.pageNum == 1) {
						this.datas = res.rows
					} else {
						this.datas = [...this.datas, ...res.rows]
					}
					console.log(this.datas.length, res.total);
					if (this.datas.length == res.total) {
						this.loading = false
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
					} else {
						this.totalBool = true
					}
					uni.stopPullDownRefresh()
				})
			},
			detail(item) {
				uni.navigateTo({
					url: "/pages/index/position/position?data=" + JSON.stringify(item)
				})
			},
			getselectApi() {
				let params = "position_type"
				getselect(params).then(res => {

					this.options = [[...[{
						dictValue: "",
						dictLabel: "全部"
					}], ...res.data]]
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						},
						{
							label: "公司信息",
							number: "0",
							id: 2
						}
					]
					console.log("全部职位：", this.options);
					this.selectValue = this.options[0][0].dictLabel
					this.form.positionType = this.options[0][0].dictValue
					this.getlistApi(this.form)
				})
			},
			optionClick(e) {
				console.log("职位：",e.value.dictLabel);
				this.selectValue=e.value[0].dictLabel
				this.form.positionType = e.value[0].dictValue
				this.indexHeaderValue = 0
				// this.form.urgentPosition = 1
				if (this.form.positionType == 1) {
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						},
						{
							label: "公司信息",
							number: "0",
							id: 2
						}
					]
				} else {
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						}
					]
				}
				this.form.pageNum = 1
				this.getlistApi(this.form)
			},
			homeConfigurationApi() {
				homeConfiguration().then(res => {
					console.log("home_pic", res);
					this.homeData = res.data
					this.ComponyHearderData.title = res.data[0].contentContents
					// this.ComponyHearderData.img = res.data[3].configurationOssUrls //logo
					// this.imageData = res.data[3].configurationOssUrls.split(",")
				})
			},
			scrolltolower(event) {
				console.log("页码:", this.form.pageNum);
				if (this.indexHeaderValue == 2) {
					return
				}
				if (!this.totalBool) {
					this.onMore = true
					this.totalBool = false
					setTimeout(() => {
						this.onMore = false
					}, 2000)
					return
				}
				this.form.pageNum++;
				this.getlistApi(this.form)
			},

			scroll(e) {
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop < 10)
			},

			scrolltoupper() {

			},
			async getselectApi_() {
				await this.getselectApi()
				await dictFunAll()
				await this.statusBack()
			},
			statusBack() {
				this.loading = false
				this.homeConfigurationApi()
				// this.getlistApi(this.form)
				return true
			}

		}
	}
</script>

<style lang="scss" scoped>
	.more {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 30px;
		width: 100%;
		font-size: 14px;
		color: #3D3D3D;
	}

	.purchase-list {

		// background-color: #f5f5f5;
		// height: calc(100vh - 50px);
		overflow: hidden;

		.purchase-body {
			// height: calc(100vh - 50px);
			overflow-y: auto;

			&::-webkit-scrollbar {
				display: none;
				/*隐藏滚动轴*/
			}
		}
	}

	.el_selects {
		margin: 7px 0px;
	}

	.indexBack1 {
		color: #2F6CBC;
	}

	.indexBack2 {
		color: #3D3D3D;
	}

	.index_header {
		margin-top: 8px;
		padding: 14px;
		// height: 54px;
		background: #FFFFFF;
		border-radius: 0px 0px 0px 0px;
		opacity: 1;

		.index_header_top {
			text {
				margin-right: 24px;
			}
		}

		.index_header_bottom {
			display: flex;
			justify-content: space-between;
			margin-top: 13px;
		}
	}

	.Inventory_compony {
		margin-top: 8px;
		padding: 12px 20px;
		background: #FFFFFF;
	}
</style>
